package first.group.ssh.packet.reader;

import first.group.ssh.packet.PacketParser;
import java.math.BigInteger;
import java.nio.ByteBuffer;

public class BigIntegerReader {
    public static BigInteger readBigInteger(ByteBuffer buffer) {
        if (!PacketParser.bufferRemains(buffer, 4)) {
            return null;
        }
        var len = buffer.getInt();
        if (!PacketParser.bufferRemains(buffer, len)) {
            return null;
        }
        
        var arr = new byte[len];
        buffer.get(arr);
        return new BigInteger(arr);
    }
}
